package com.util;

import java.util.Random;

public class RandomUtil {
	private static Random randGen = null;
	private static Random numrandGen = null;
	
	private static char[] bersAndLetters = null;
	private static char[] numbersAndLetters = null;
	public static String getRandom(int length){
		if (length < 1) {
			return null;
		}
		if (randGen == null) {
			randGen = new Random();
			bersAndLetters = ("0123456789abcdefghijklmnopqrstuvwxyz" +
				"ABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray();
		}
		char [] randBuffer = new char[length];
		for (int i=0; i<length; i++) {
			randBuffer[i] = bersAndLetters[randGen.nextInt(61)];
		}
			return new String(randBuffer);
	}
	
	
	
		public static String getRandomShuzi(int length){
			if (length < 1) {
				return null;
			}
			if (numrandGen == null) {
				numrandGen = new Random();
				numbersAndLetters = ("0123456789").toCharArray();
			}
			char [] randBuffer = new char[length];
			for (int i=0; i<randBuffer.length; i++) {
				randBuffer[i] = numbersAndLetters[numrandGen.nextInt(10)];
			}
				return new String(randBuffer);
			}
	
	/*public static void main(String[] args) {
		Random random = new Random();
		char[] c = "0123456789".toCharArray();
		char[] b = new char[4];
		for (int i = 0; i < b.length; i++) {
			b[i] = c[random.nextInt(9)];
		}
			System.out.println(new String(b));
	}*/
}
